package atm;

import java.util.Scanner;

public class ATM01 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("欢迎来到牛逼银行");
        String sysAccount = "520";
        String sysPwd = "159357";
        double sysBlance = 0;
        //登录判断
        for (int i = 2;i > -1;i--) {

            System.out.println("请输入账号：");
            String account = sc.next();
            System.out.println("请输入密码：");
            String pwd = sc.next();

            //三次比较，如果连续失败则系统退出
            if (sysAccount.equals(account) && sysPwd.equals(pwd)) {
                while (true) {
                    //如果登陆成功，进入菜单界面
                    System.out.println("请选择：1-存款 2-取款 3-查询 4-退出");
                    int input = sc.nextInt();
                    if (input == 1) {
                        System.out.println("请输入存款金额：");
                        double blance = sc.nextInt();
                        if (blance > 0){
                            sysBlance += blance;
                            System.out.println("存款成功" + "\n" + "账户余额为" + sysBlance);
                        }else {
                            System.out.println("输入错误");
                        }
                    } else if (input == 2) {
                        System.out.println("请输入取款金额：");
                        double blance = sc.nextInt();
                        sysBlance -= blance;
                        if (blance > 0 && blance <= sysBlance) {
                            System.out.println("存款成功" + "\n" + "账户余额为" + sysBlance);
                        }else {
                            System.out.println("输入金额错误");
                        }
                    } else if (input == 3) {
                        System.out.println("账户金额余额" + sysBlance + "元");
                    } else if (input == 4) {
                        //系统结束
                        System.out.println("再见");
                        System.exit(0);
                    } else {
                        System.out.println("输入金额有误");
                    }
                }
            } else {
                System.out.println("账户密码输入错误" + "\n" + "您还有" + i + "机会");
                if (i == 0){
                    System.out.println("错误三次，系统自动退出");
                    System.exit(0);
                }
            }
        }
    }
}
